package com.kintreda.ieco_server.bean.account;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.kintreda.ieco_server.bean.system.BaseVo;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * 用户菜单新表
 * @author HuangZhongYao
 *
 */
@Entity
@Table(name = "common_menu")
public class Menu extends BaseVo {
	
	private static final long serialVersionUID = 1L;

	private String name; // 菜单名称
	private String pid = "-1"; // 父级菜单
	private String url; // 菜单url
	private String identification; // 菜单标识
	private String des;
	private String menuButton;//按钮或图标 menu | button
	private String icoUrl;//菜单图标
	//菜单排序
	private int orderNum = 1;

	//------------------------临时变量------------------------------
	@Transient
	@JsonIgnore
	private List<Menu> children = new ArrayList<Menu>();

	@ManyToMany(mappedBy = "menus")
	@JsonIgnore
	private Set<Role> roles; // 角色列表
	
	@Transient
	@JsonIgnore
	private Menu parentMenu;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPid() {
		return pid;
	}

	public void setPid(String pid) {
		this.pid = pid;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getIdentification() {
		return identification;
	}

	public void setIdentification(String identification) {
		this.identification = identification;
	}

	public String getDes() {
		return des;
	}

	public void setDes(String des) {
		this.des = des;
	}

	public List<Menu> getChildren() {
		return children;
	}

	public void setChildren(List<Menu> children) {
		this.children = children;
	}

	public Menu getParentMenu() {
		return parentMenu;
	}

	public void setParentMenu(Menu parentMenu) {
		this.parentMenu = parentMenu;
	}

	public int getOrderNum() {
		return orderNum;
	}

	public void setOrderNum(int orderNum) {
		this.orderNum = orderNum;
	}

	public String getMenuButton() {
		return menuButton;
	}

	public void setMenuButton(String menuButton) {
		this.menuButton = menuButton;
	}

	public String getIcoUrl() {
		return icoUrl;
	}

	public void setIcoUrl(String icoUrl) {
		this.icoUrl = icoUrl;
	}

	@Override
	public int hashCode() {
		return super.getId().hashCode() + this.name.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		
		if(obj == null) {
			return true;
		}
		
		if(!(obj instanceof Menu)) {
            return false;
        }
		
		Menu menu = (Menu)obj;
		
		return (menu.getId().equals(super.getId()) && menu.getName().equals(this.name));
	}

	public Set<Role> getRoles() {
		return roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}
}
